using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace BookShop
{
	/// <summary>
	/// Strongly-typed collection for the PurchaseApply class.
	/// </summary>
    [Serializable]
	public partial class PurchaseApplyCollection : ActiveList<PurchaseApply, PurchaseApplyCollection>
	{	   
		public PurchaseApplyCollection() {}
        
        /// <summary>
		/// Filters an existing collection based on the set criteria. This is an in-memory filter
		/// Thanks to developingchris for this!
        /// </summary>
        /// <returns>PurchaseApplyCollection</returns>
		public PurchaseApplyCollection Filter()
        {
            for (int i = this.Count - 1; i > -1; i--)
            {
                PurchaseApply o = this[i];
                foreach (SubSonic.Where w in this.wheres)
                {
                    bool remove = false;
                    System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
                    if (pi.CanRead)
                    {
                        object val = pi.GetValue(o, null);
                        switch (w.Comparison)
                        {
                            case SubSonic.Comparison.Equals:
                                if (!val.Equals(w.ParameterValue))
                                {
                                    remove = true;
                                }
                                break;
                        }
                    }
                    if (remove)
                    {
                        this.Remove(o);
                        break;
                    }
                }
            }
            return this;
        }
		
		
	}
	/// <summary>
	/// This is an ActiveRecord class which wraps the PurchaseApply table.
	/// </summary>
	[Serializable]
	public partial class PurchaseApply : ActiveRecord<PurchaseApply>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public PurchaseApply()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}
		
		private void InitSetDefaults() { SetDefaults(); }
		
		public PurchaseApply(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}
        
		public PurchaseApply(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}
		 
		public PurchaseApply(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}
		
		protected static void SetSQLProps() { GetTableSchema(); }
		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}
		}
		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("PurchaseApply", TableType.Table, DataService.GetInstance("BookShop"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarPuchaseApplyID = new TableSchema.TableColumn(schema);
				colvarPuchaseApplyID.ColumnName = "PuchaseApplyID";
				colvarPuchaseApplyID.DataType = DbType.AnsiStringFixedLength;
				colvarPuchaseApplyID.MaxLength = 20;
				colvarPuchaseApplyID.AutoIncrement = false;
				colvarPuchaseApplyID.IsNullable = false;
				colvarPuchaseApplyID.IsPrimaryKey = true;
				colvarPuchaseApplyID.IsForeignKey = false;
				colvarPuchaseApplyID.IsReadOnly = false;
				colvarPuchaseApplyID.DefaultSetting = @"";
				colvarPuchaseApplyID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPuchaseApplyID);
				
				TableSchema.TableColumn colvarApplyDate = new TableSchema.TableColumn(schema);
				colvarApplyDate.ColumnName = "ApplyDate";
				colvarApplyDate.DataType = DbType.DateTime;
				colvarApplyDate.MaxLength = 0;
				colvarApplyDate.AutoIncrement = false;
				colvarApplyDate.IsNullable = true;
				colvarApplyDate.IsPrimaryKey = false;
				colvarApplyDate.IsForeignKey = false;
				colvarApplyDate.IsReadOnly = false;
				colvarApplyDate.DefaultSetting = @"";
				colvarApplyDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplyDate);
				
				TableSchema.TableColumn colvarApplyDepartment = new TableSchema.TableColumn(schema);
				colvarApplyDepartment.ColumnName = "ApplyDepartment";
				colvarApplyDepartment.DataType = DbType.AnsiString;
				colvarApplyDepartment.MaxLength = 50;
				colvarApplyDepartment.AutoIncrement = false;
				colvarApplyDepartment.IsNullable = false;
				colvarApplyDepartment.IsPrimaryKey = true;
				colvarApplyDepartment.IsForeignKey = false;
				colvarApplyDepartment.IsReadOnly = false;
				colvarApplyDepartment.DefaultSetting = @"";
				colvarApplyDepartment.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplyDepartment);
				
				TableSchema.TableColumn colvarApplyReason = new TableSchema.TableColumn(schema);
				colvarApplyReason.ColumnName = "ApplyReason";
				colvarApplyReason.DataType = DbType.AnsiString;
				colvarApplyReason.MaxLength = 50;
				colvarApplyReason.AutoIncrement = false;
				colvarApplyReason.IsNullable = true;
				colvarApplyReason.IsPrimaryKey = false;
				colvarApplyReason.IsForeignKey = false;
				colvarApplyReason.IsReadOnly = false;
				colvarApplyReason.DefaultSetting = @"";
				colvarApplyReason.ForeignKeyTableName = "";
				schema.Columns.Add(colvarApplyReason);
				
				TableSchema.TableColumn colvarPickingType = new TableSchema.TableColumn(schema);
				colvarPickingType.ColumnName = "PickingType";
				colvarPickingType.DataType = DbType.AnsiStringFixedLength;
				colvarPickingType.MaxLength = 10;
				colvarPickingType.AutoIncrement = false;
				colvarPickingType.IsNullable = true;
				colvarPickingType.IsPrimaryKey = false;
				colvarPickingType.IsForeignKey = false;
				colvarPickingType.IsReadOnly = false;
				colvarPickingType.DefaultSetting = @"";
				colvarPickingType.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPickingType);
				
				TableSchema.TableColumn colvarRemark = new TableSchema.TableColumn(schema);
				colvarRemark.ColumnName = "Remark";
				colvarRemark.DataType = DbType.AnsiString;
				colvarRemark.MaxLength = 100;
				colvarRemark.AutoIncrement = false;
				colvarRemark.IsNullable = true;
				colvarRemark.IsPrimaryKey = false;
				colvarRemark.IsForeignKey = false;
				colvarRemark.IsReadOnly = false;
				colvarRemark.DefaultSetting = @"";
				colvarRemark.ForeignKeyTableName = "";
				schema.Columns.Add(colvarRemark);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["BookShop"].AddSchema("PurchaseApply",schema);
			}
		}
		#endregion
		
		#region Props
		  
		[XmlAttribute("PuchaseApplyID")]
		[Bindable(true)]
		public string PuchaseApplyID 
		{
			get { return GetColumnValue<string>(Columns.PuchaseApplyID); }
			set { SetColumnValue(Columns.PuchaseApplyID, value); }
		}
		  
		[XmlAttribute("ApplyDate")]
		[Bindable(true)]
		public DateTime? ApplyDate 
		{
			get { return GetColumnValue<DateTime?>(Columns.ApplyDate); }
			set { SetColumnValue(Columns.ApplyDate, value); }
		}
		  
		[XmlAttribute("ApplyDepartment")]
		[Bindable(true)]
		public string ApplyDepartment 
		{
			get { return GetColumnValue<string>(Columns.ApplyDepartment); }
			set { SetColumnValue(Columns.ApplyDepartment, value); }
		}
		  
		[XmlAttribute("ApplyReason")]
		[Bindable(true)]
		public string ApplyReason 
		{
			get { return GetColumnValue<string>(Columns.ApplyReason); }
			set { SetColumnValue(Columns.ApplyReason, value); }
		}
		  
		[XmlAttribute("PickingType")]
		[Bindable(true)]
		public string PickingType 
		{
			get { return GetColumnValue<string>(Columns.PickingType); }
			set { SetColumnValue(Columns.PickingType, value); }
		}
		  
		[XmlAttribute("Remark")]
		[Bindable(true)]
		public string Remark 
		{
			get { return GetColumnValue<string>(Columns.Remark); }
			set { SetColumnValue(Columns.Remark, value); }
		}
		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varPuchaseApplyID,DateTime? varApplyDate,string varApplyDepartment,string varApplyReason,string varPickingType,string varRemark)
		{
			PurchaseApply item = new PurchaseApply();
			
			item.PuchaseApplyID = varPuchaseApplyID;
			
			item.ApplyDate = varApplyDate;
			
			item.ApplyDepartment = varApplyDepartment;
			
			item.ApplyReason = varApplyReason;
			
			item.PickingType = varPickingType;
			
			item.Remark = varRemark;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varPuchaseApplyID,DateTime? varApplyDate,string varApplyDepartment,string varApplyReason,string varPickingType,string varRemark)
		{
			PurchaseApply item = new PurchaseApply();
			
				item.PuchaseApplyID = varPuchaseApplyID;
			
				item.ApplyDate = varApplyDate;
			
				item.ApplyDepartment = varApplyDepartment;
			
				item.ApplyReason = varApplyReason;
			
				item.PickingType = varPickingType;
			
				item.Remark = varRemark;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}
		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn PuchaseApplyIDColumn
        {
            get { return Schema.Columns[0]; }
        }
        
        
        
        public static TableSchema.TableColumn ApplyDateColumn
        {
            get { return Schema.Columns[1]; }
        }
        
        
        
        public static TableSchema.TableColumn ApplyDepartmentColumn
        {
            get { return Schema.Columns[2]; }
        }
        
        
        
        public static TableSchema.TableColumn ApplyReasonColumn
        {
            get { return Schema.Columns[3]; }
        }
        
        
        
        public static TableSchema.TableColumn PickingTypeColumn
        {
            get { return Schema.Columns[4]; }
        }
        
        
        
        public static TableSchema.TableColumn RemarkColumn
        {
            get { return Schema.Columns[5]; }
        }
        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string PuchaseApplyID = @"PuchaseApplyID";
			 public static string ApplyDate = @"ApplyDate";
			 public static string ApplyDepartment = @"ApplyDepartment";
			 public static string ApplyReason = @"ApplyReason";
			 public static string PickingType = @"PickingType";
			 public static string Remark = @"Remark";
						
		}
		#endregion
		
		#region Update PK Collections
		
        #endregion
    
        #region Deep Save
		
        #endregion
	}
}
